<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 18:20:48
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-07-25 15:23:57
-->
<!-- 老人服务管理 -->
<template>
  <BaseContainer>
    <aplid-base-crud ref="crud" class="w-100" v-bind="baseConfig" :paramsObj="{creditCode}">
      <template #menuColumn="{row}">
        <el-button v-if="judgeCanCancel(row)" text type="primary" @click="toRemark(row)">撤销</el-button>
      </template>
    </aplid-base-crud>
  </BaseContainer>
</template>

<script setup lang="ts">
import { baseConfig } from './config'
import apiMod from '@/apiMod/index'
import { getStore } from '@/utils/store'
import {ElMessageBox} from 'element-plus'
const userInfo = getStore('userInfo') ||{}

let creditCode = userInfo.organizationId
creditCode = creditCode==1?undefined:creditCode

// 判断是否可以撤销
const judgeCanCancel = (row) => {
  if(row&&row.resignationTime&&row.status!=1){
    let newTime = new Date().getTime()
    let end = new Date(row.resignationTime).getTime()
    if(newTime-end<0){
      return true
    }else{
      return false
    }
  }
}
let crud = ref()
const handleRefreshPage = () => {
  nextTick(() => {
    crud.value.refreshChange({}, false)
  })
}
// 撤销
const toRemark = (row) =>{
  ElMessageBox.confirm(
    `将撤销当前${row.name}的离职,是否继续?`,
    '提示',
    {
      confirmButtonText: '确定',
      cancelButtonText: '关闭',
      type: 'warning',
    }
  )
    .then(() => {
      apiMod.view_dpEmployeeResignationRecord_revoke({id:row.id}).then(res=>{
        ElMessage({
          type: 'success',
          message: '撤销成功',
        })
        handleRefreshPage()
      })
    })
    .catch(() => {
      
    })
}
</script>

<style scoped></style>